package com.diyunapp.xilinapp.myindent;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.base.BaseActivity;
import com.diyunapp.xilinapp.fragments.AllIntentsFragment;
import com.diyunapp.xilinapp.fragments.WaitEvaluateFragment;
import com.diyunapp.xilinapp.fragments.WaitPayFragment;
import com.diyunapp.xilinapp.fragments.WaitReceiveFragment;
import com.diyunapp.xilinapp.fragments.WaitSendFragment;

import java.util.ArrayList;
import java.util.List;

public class IntentActivity extends BaseActivity {
    private ViewPager viewPager;
    private TabLayout tabLayout;
    private AllIntentPagerAdapter allIntentPagerAdapter;
    private List<Fragment> fragments = new ArrayList<Fragment>();

    private String[] tabs = {"全部","待付款","待发货","待收货","待评价"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent);

        int current=getIntent().getIntExtra("current",0);
        switchViewPager(current);

    }

    private void switchViewPager(int current) {
        switch(current){
            case 1:
                fragments.add(new WaitPayFragment());
                break;

        }
    }

    public void initView(){
        fragments.add(new AllIntentsFragment());//0
        fragments.add(new WaitPayFragment());//1
        fragments.add(new WaitSendFragment());//2
        fragments.add(new WaitReceiveFragment());//3
        fragments.add(new WaitEvaluateFragment());//4
        allIntentPagerAdapter = new AllIntentPagerAdapter(getSupportFragmentManager());
        viewPager = (ViewPager) findViewById(R.id.invest_view_pager);
        viewPager.setAdapter(allIntentPagerAdapter);
        tabLayout = (TabLayout) findViewById(R.id.invest_tab);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setTabsFromPagerAdapter(allIntentPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);

    }
    class AllIntentPagerAdapter extends FragmentStatePagerAdapter {


        public AllIntentPagerAdapter(android.support.v4.app.FragmentManager fm) {
            super(fm);
        }

        @Override
        public android.support.v4.app.Fragment getItem(int position) {
            return fragments==null?null:fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments==null?0:fragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tabs[position];
        }
    }
}
